<?php

/**
 * This is the model class for table "product".
 *
 * The followings are the available columns in table 'product':
 * @property integer $id
 * @property string $model
 * @property string $name
 * @property integer $category
 * @property string $image
 * @property string $image_thumb
 * @property string $highlight
 * @property string $overview
 * @property string $features
 * @property string $specifications
 * @property string $downloads
 *
 * The followings are the available model relations:
 * @property Category $category0
 */
class Product extends CActiveRecord
{
	public $file;
        /**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Product the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'product';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
                        array('file','file','types'=>'jpg, gif, png','allowEmpty'=>false),
			array('model, name, category, highlight, overview, features, specifications', 'required'),
			array('category', 'numerical', 'integerOnly'=>true),
			array('model', 'length', 'max'=>100),
			array('name, image, image_thumb', 'length', 'max'=>255),
			array('downloads', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, model, name, category, image, image_thumb, highlight, overview, features, specifications, downloads', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cat' => array(self::BELONGS_TO, 'Category', 'category'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'model' => 'Model',
			'name' => 'Name',
			'category' => 'Category',
			'image' => 'Image',
			'image_thumb' => 'Image Thumb',
			'highlight' => 'Highlight',
			'overview' => 'Overview',
			'features' => 'Features',
			'specifications' => 'Specifications',
			'downloads' => 'Downloads',
                        'file' => 'Image file'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('model',$this->model,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('category',$this->category);
		$criteria->compare('image',$this->image,true);
		$criteria->compare('image_thumb',$this->image_thumb,true);
		$criteria->compare('highlight',$this->highlight,true);
		$criteria->compare('overview',$this->overview,true);
		$criteria->compare('features',$this->features,true);
		$criteria->compare('specifications',$this->specifications,true);
		$criteria->compare('downloads',$this->downloads,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}